<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="utf-8">
  <title></title>
  <link rel="stylesheet" href="/login/css/style.css">
</head>

<body style="background-image: url(../login/images/bg.jpg)">
<div class="content">
  <div class="form sign-in">
    <h2>欢迎回来</h2>
    <label>
      <span>邮箱</span>
      <input type="email" value="admin@qa.com" id="loginEmail"/>
    </label>
    <label>
      <span>密码</span>
      <input type="password" value="123" id="loginPassword"/>
    </label>
    <!--<p class="forgot-pass"><a href="javascript:">忘记密码？</a></p>-->
    <button type="button" onclick="login()" class="submit">登 录</button>

  </div>
  <div class="sub-cont">
    <div class="img">
      <div class="img__text m--up">
        <h2>还未注册？</h2>
        <p>立即注册，了解更多知识！</p>
      </div>
      <div class="img__text m--in">
        <h2>已有帐号？</h2>
        <p>有帐号就登录吧，好久不见了！</p>
      </div>
      <div class="img__btn">
        <span class="m--up">注 册</span>
        <span class="m--in">登 录</span>
      </div>
    </div>
    <div class="form sign-up">
      <h2>立即注册</h2>
      <label>
        <span>用户名</span>
        <input type="text" id="registerName"/>
      </label>
      <label>
        <span>邮箱</span>
        <input type="email" id="registerEmail"/>
      </label>
      <label>
        <span>密码</span>
        <input type="password" id="registerPassword"/>
      </label>
      <button type="button" onclick="register()" class="submit">注 册</button>

    </div>
  </div>
</div>
<script src="/login/js/script.js"></script>
<script src="/js/jquery.min.js"></script>
<script>
  function login() {
    var loginEmail = $("#loginEmail").val();
    if (!loginEmail) {
      alert("请输入邮箱");
      return false;
    }

    var loginPassword = $("#loginPassword").val();
    if (!loginPassword) {
      alert("请输入密码");
      return false;
    }

    $.ajax({
      url: '/user/login',
      dataType: 'JSON',
      type: 'POST',
      data: {
        email: loginEmail,
        password: loginPassword
      },
      success: function (result) {
        if (result.code == 200) {
            if (result.data.role ==1) {
              window.location.href = '/cms/index';
            } else {

              window.location.href='/reception/index';
            }
        } else {
          alert(result.msg);
          return false;
        }
      }
    })
  }

  function register() {
    var registerName = $("#registerName").val();
    if (!registerName) {
      alert("请输入用户名");
      return false;
    }
    var registerEmail = $("#registerEmail").val();
    if (!registerEmail) {
      alert("请输入用户邮箱")
      return false;
    }
    var registerPassword = $("#registerPassword").val();
    if (!registerPassword) {
      alert("请输入密码")
      return false;
    }

    $.ajax({
      url: '/user/register',
      dataType: 'JSON',
      type: 'POST',
      data: {
        name:registerName,
        email: registerEmail,
        password: registerPassword
      },
      success: function (result) {
        if (result.code == 200) {
          alert(result.msg)
          window.location.href='/user/loginPage';
        } else {
          alert(result.msg);
          return false;
        }
      }
    })

  }
</script>
</body>

</html>